package dao

import (
	"gorm.io/gorm"
	"zg3zk3/inits"
	"zg3zk3/model"
)

func CreateArt(title string, context string, userId int) (err error) {
	result := &model.Article{
		UserId:  userId,
		Title:   title,
		Context: context,
	}
	if err = inits.DB.Create(&result).Error; err != nil {
		return err
	}
	return nil
}
func GetArtList() *gorm.DB {
	artList := inits.DB.Raw("SELECT * FROM articles LEFT JOIN follows ON articles.user_id = follows.user_id  ORDER BY follows.follow_id,articles.like_count ASC")
	return artList

}
